import 'package:flutter/material.dart';

class PPInterestOptionsTopicalItem extends StatefulWidget {

    PPInterestOptionsTopicalItem({Key key, this.data, this.itemWidth = 100, this.action}) : super(key: key);

    final Map data;
    final double itemWidth;
    final Function action;

    _PPInterestOptionsTopicalItemState createState() => _PPInterestOptionsTopicalItemState();
}

class _PPInterestOptionsTopicalItemState extends State<PPInterestOptionsTopicalItem> {

    Map data;
    double itemWidth;

    @override
    void initState() {
        data = widget.data;
        itemWidth = widget.itemWidth;
        super.initState();
    }

    @override
    Widget build(BuildContext context) {
        return (Container(
            margin: EdgeInsets.only(bottom: 4),
            child: FlatButton(
                padding: EdgeInsets.all(0),
                child: Container(
                width: itemWidth,
                padding: EdgeInsets.only(left: 14),
                decoration: BoxDecoration(
                    border: Border(left: BorderSide(width: 6, color: _getBorderColor()))),
                    child: Text(data["title"], style: TextStyle(fontSize: 14, fontWeight: FontWeight.w400, color: Color.fromRGBO(0, 0, 0, 1)))
                ),
                onPressed: _onClick,
            ),
        ));
    }

    _getBorderColor() {
        if(data["isSelect"]) {
            return Color.fromRGBO(63, 227, 206, 1);
        } else {
            return Colors.transparent;
        }
    }

    _onClick() {
        if(widget.action != null) {
            widget.action(data);
        }
    }
}
